#!/bin/bash

#----------------------------------------------------------------------
#set -o xtrace

if [ ! -d wx/lib ]; then  # TODO: make this test more robust
    echo "Please run this script from the root wxPython directory."
    exit 1
fi

#set -o xtrace

VERSION=`python -c "import setup;print setup.VERSION"`
DEST=wxPython-$VERSION/docs


# **** Make a directory to build up a distribution tree
mkdir -p _build_docs/$DEST
cd _build_docs
rm -rf $DEST/wx

DEST=`abspath.py $DEST`

if [ "$WXWIN" != "" ]; then
    WXDIR=$WXWIN
else
    WXDIR=`abspath.py ../../wxWidgets`
fi


# **** Run the docs build script, that runs doxygen for us.  Use the
#      chm target so we get the HTMLHelp control files too.
if [ "$1" = "clean" ]; then
    rm -r $WXDIR/docs/doxygen/out
fi
$WXDIR/docs/doxygen/regen.sh chm


# **** Copy to our build dir and clean up
cp -R $WXDIR/docs/doxygen/out/html $DEST/wx
rm $DEST/wx/*.map
rm $DEST/wx/*.md5


# # **** zip the docs into "books"
# pushd $DEST
# pushd wx
# zip ../wx.zip *
# popd
# rm -r wx

# for c in $CONTRIBS; do
#     pushd $c
#     zip ../$c.zip *
#     popd
#     rm -r $c
# done

# popd
# cp ../distrib/viewdocs.py $DEST
# cp ../distrib/README.viewdocs.txt $DEST/README.txt


mkdir -p ../dist
rm -f ../dist/wxPython-docs-$VERSION.tar.bz2
tar cvf ../dist/wxPython-docs-$VERSION.tar wxPython-$VERSION
bzip2 -9 ../dist/wxPython-docs-$VERSION.tar


# **** Cleanup
cd ..
rm -r _build_docs


